package com.zhxh.nzpos.setting;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.zhxh.nzpos.BaseActivity;
import com.zhxh.nzpos.R;

/**
 * 系统设定主界面
 * 
 * @author wangzt
 *
 */
public class SettingManageActivity extends BaseActivity {
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_manage);
        initViews();
    }
	
	private void initViews() {
		GridView gridView = (GridView) findViewById(R.id.grid_setting);

		ArrayList<HashMap<String, Object>> imagelist = new ArrayList<HashMap<String, Object>>();
		//价格设定移到商品管理
/*		HashMap<String, Object> map1 = new HashMap<String, Object>();
		map1.put("image", R.drawable.setting_price);
		//map1.put("text", getResources().getString(R.string.price_setting));
		imagelist.add(map1);*/
		HashMap<String, Object> map2 = new HashMap<String, Object>();
		map2.put("image", R.drawable.setting_time);
		//map2.put("text", getResources().getString(R.string.time_setting));
		imagelist.add(map2);
		HashMap<String, Object> map3 = new HashMap<String, Object>();
		map3.put("image", R.drawable.setting_password);
		//map3.put("text", getResources().getString(R.string.password_setting));
		imagelist.add(map3);
		HashMap<String, Object> map4 = new HashMap<String, Object>();
		map4.put("image", R.drawable.setting_operator);
		//map4.put("text", getResources().getString(R.string.operator_setting));
		imagelist.add(map4);
		HashMap<String, Object> map5 = new HashMap<String, Object>();
		map5.put("image", R.drawable.setting_system);
		//map5.put("text", getResources().getString(R.string.sys_setting));
		imagelist.add(map5);
		SharedPreferences sharedata = getSharedPreferences("PreferencesFile", 0);  
		String user = sharedata.getString("user", null);  
		
		//if("admin".equals(user)) {
			HashMap<String, Object> map6 = new HashMap<String, Object>();
			map6.put("image", R.drawable.setting_init);
			//map6.put("text", getResources().getString(R.string.init_setting));
			imagelist.add(map6);
		//}
		

		
		SimpleAdapter simpleAdapter = new SimpleAdapter(this, imagelist,
				R.layout.compose_grid_item, new String[] { "image", "text" },
				new int[] { R.id.compose_grid_image, R.id.compose_grid_text });
		gridView.setAdapter(simpleAdapter);
		
		gridView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				Intent intent = new Intent();
				switch (pos) {
				/*case 0:
					intent.setClass(getApplicationContext(), PriceSettingActivity.class);
					startActivity(intent);
					break;*/
				case 0:
					intent.setClass(getApplicationContext(), TimeSettingActivity.class);
					startActivity(intent);
					break;
				case 1:
					intent.setClass(getApplicationContext(), PasswordSettingActivity.class);
					startActivity(intent);
					break;
				case 2:
					intent.setClass(getApplicationContext(), OperatorSettingActivity.class);
					startActivity(intent);
					break;
				case 3:
					intent.setClass(getApplicationContext(), SystemSettingActivity.class);
					startActivity(intent);
					break;
				case 4:
					intent.setClass(getApplicationContext(), InitSettingActivity.class);
					startActivity(intent);
					break;

				}
			}
		});
	}
}
